<?php

	// TITLE: Home_owner_requirement AUTO MODEL
	// FILE: scaffolding/model/home_owner_requirement.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createHomeOwnerRequirement = function($con, $homeOwnerRequirement) {
		$sql = 'INSERT INTO home_owner_requirement (homeowner_id, requirement_id, when_completed, who_entered, when_entered, who_authorized, when_authorized) VALUES (';
		$sql .= $home_owner_requirement->getHomeownerId() . ', ';
		$sql .= $home_owner_requirement->getRequirementId() . ', ';
		$sql .= $home_owner_requirement->getWhenCompleted() . ', ';
		$sql .= $home_owner_requirement->getWhoEntered() . ', ';
		$sql .= $home_owner_requirement->getWhenEntered() . ', ';
		$sql .= $home_owner_requirement->getWhoAuthorized() . ', ';
		$sql .= $home_owner_requirement->getWhenAuthorized() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readHomeOwnerRequirement = function($con, $id) {
		$sql = 'SELECT * FROM home_owner_requirement WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$homeOwnerRequirement = new HomeOwnerRequirement();
			$homeOwnerRequirement->setHomeownerId($dbio->select($readHomeowner(result[0])));
			$homeOwnerRequirement->setRequirementId($dbio->select($readRequirement(result[1])));
			$homeOwnerRequirement->setWhenCompleted(result[2]);
			$homeOwnerRequirement->setWhoEntered(result[3]);
			$homeOwnerRequirement->setWhenEntered(result[4]);
			$homeOwnerRequirement->setWhoAuthorized(result[5]);
			$homeOwnerRequirement->setWhenAuthorized(result[6]);
		} else {
			$homeOwnerRequirement = false;
		}
		return $homeOwnerRequirement;
	};

	$updateHomeOwnerRequirement = function($con, $homeOwnerRequirement) {
		$sql = 'UPDATE home_owner_requirement SET ';
		$sql .= 'homeowner_id = ' . $home_owner_requirement->getHomeownerId() . ', ';
		$sql .= 'requirement_id = ' . $home_owner_requirement->getRequirementId() . ', ';
		$sql .= 'when_completed = ' . $home_owner_requirement->getWhenCompleted() . ', ';
		$sql .= 'who_entered = ' . $home_owner_requirement->getWhoEntered() . ', ';
		$sql .= 'when_entered = ' . $home_owner_requirement->getWhenEntered() . ', ';
		$sql .= 'who_authorized = ' . $home_owner_requirement->getWhoAuthorized() . ', ';
		$sql .= 'when_authorized = ' . $home_owner_requirement->getWhenAuthorized() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteHomeOwnerRequirement = function($con, $id) {
		$sql = 'DELETE FROM home_owner_requirement WHERE homeowner_id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listHomeOwnerRequirement = function($con) {
		$sql = 'SELECT * FROM home_owner_requirement';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$homeOwnerRequirements = array();
			while ($result = mysqli_fetch_array($results)) {
				$homeOwnerRequirement = new HomeOwnerRequirement();
				$homeOwnerRequirement->setHomeownerId($dbio->select($readHomeowner(result[0])));
				$homeOwnerRequirement->setRequirementId($dbio->select($readRequirement(result[1])));
				$homeOwnerRequirement->setWhenCompleted(result[2]);
				$homeOwnerRequirement->setWhoEntered(result[3]);
				$homeOwnerRequirement->setWhenEntered(result[4]);
				$homeOwnerRequirement->setWhoAuthorized(result[5]);
				$homeOwnerRequirement->setWhenAuthorized(result[6]);
				$homeOwnerRequirements[] = homeOwnerRequirement;
			}// end while
		} else {
			$homeOwnerRequirements = false;
		}
		return $homeOwnerRequirements;
	};

